package com.opencv.formatter;

import com.fasterxml.jackson.core.JsonGenerator;
import com.fasterxml.jackson.databind.JsonSerializer;
import com.fasterxml.jackson.databind.SerializerProvider;

import java.io.IOException;
import java.util.Date;
import java.util.Objects;

/**
 * @author qz.wu
 * @date 2021/11/23 18:19
 * @descriptions Date类型转Long的序列化
 */
public class LongSerializer extends JsonSerializer<Date> {

    @Override
    public void serialize(Date date, JsonGenerator jsonGenerator, SerializerProvider serializerProvider)
        throws IOException {
        Long output = null;
        if (Objects.nonNull(date)) {
            output = date.getTime();
        }
        jsonGenerator.writeString(String.valueOf(output.longValue()));
    }
}
